package com.hs.excel.demos.service.transform;

import com.hs.excel.demos.listenter.Comont;
import com.hs.excel.demos.pojo.RequestParm;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class OracleTransform {

   public void oneInsert(RequestParm requestParm, Map<Integer, String> head,Map<String, String> data){
       StringBuffer  stringBuffer = new StringBuffer("insert into");
       stringBuffer.append(" " + requestParm.getTableName() + "(");

       List<String> heads = new ArrayList<>(head.values());
       for (String h : heads) {
           String s = h + ",";
           stringBuffer.append(s);
       }
       stringBuffer.deleteCharAt(stringBuffer.length() - 1);
       stringBuffer.append(") ");
       stringBuffer.append("VALUES(");
       List<String> values = new ArrayList<>(data.values());
       for (String filed : values) {
           if (filed == null) {
               String s = "'',";
               stringBuffer.append(s);
           } else {
               String s = "'" + filed + "'" + ",";
               stringBuffer.append(s);
           }
       }
       stringBuffer.deleteCharAt(stringBuffer.length() - 1);
       stringBuffer.append("); ");
       Comont.insertList.add(stringBuffer.toString());
   }

    public void entiretyOracleHandle(Map<String, String> data, Map<Integer, String> head,RequestParm requestParm) {
        List<String> heads = new ArrayList<>(head.values());
        StringBuffer  stringBuffer = new StringBuffer("into " + requestParm.getTableName() + "(");
        for (String h : heads) {
            String s = h + ",";
            stringBuffer.append(s);
        }
        stringBuffer.deleteCharAt(stringBuffer.length() - 1);
        stringBuffer.append(") ");
        stringBuffer.append("VALUES(");
        List<String> values = new ArrayList<>(data.values());
        for (String filed : values) {
            if (filed == null) {
                String s = "'',";
                stringBuffer.append(s);
            } else {
                String s = "'" + filed + "'" + ",";
                stringBuffer.append(s);
            }
        }
        stringBuffer.deleteCharAt(stringBuffer.length() - 1);
        stringBuffer.append(")");
        Comont.insertList.add(stringBuffer.toString());
    }


    public void entiretyOracleEnd() {
        StringBuilder s = new StringBuilder("insert all");
        Comont.insertList.add(0, s.toString());
        Comont.insertList.add("SELECT * FROM dual;");
    }

}
